package com.yitao.cms.controller.intergenix;

import com.skipper.base.json.JSONObject;
import com.yitao.cms.service.exchangeRate.ExchangeRateService;
import com.yitao.cms.service.order.CmsOrderLogisticaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 供应链项目调用相关接口
 *
 * @Date: 2019/12/5 11:41
 * @Author: Kien
 */
@RestController
@RequestMapping(value = "/cms/intergenix", produces = {"application/json"})
@Api(description = "货币汇率", tags = {"cms-intergenix"})
public class IntergenixController {
    @Autowired
    private ExchangeRateService exchangeRateService;
    @Autowired
    private CmsOrderLogisticaskService cmsOrderLogisticaskService;

    @ApiOperation("获取澳元汇率-只返回最新的一条")
    @RequestMapping(value = "/getExchangeRate", method = RequestMethod.POST)
    public JSONObject getExchangeRate(@ApiParam(value = "源币种", required = true) @RequestParam(value = "sourceCurrency") String sourceCurrency){
        return exchangeRateService.findNewExchangeRate(sourceCurrency);
    }

    @ApiOperation("添加爬取物流信息单号")
    @RequestMapping(value = "/saveLogistic", method = RequestMethod.POST)
    public JSONObject saveLogistic(@ApiParam(value = "物流商编码", required = true) @RequestParam(value = "logisticCode") String logisticCode,
                                   @ApiParam(value = "物流商名称", required = true) @RequestParam(value = "logisticName") String logisticName,
                                   @ApiParam(value = "物流单号", required = true) @RequestParam(value = "logisticNumber") String logisticNumber){
        return cmsOrderLogisticaskService.saveLogistic(logisticCode, logisticName, logisticNumber);
    }

    @ApiOperation("批量获取物流信息")
    @RequestMapping(value = "/getLogisticDetail", method = RequestMethod.POST)
    public JSONObject getLogisticDetail(HttpServletRequest request){
        String paramsList = request.getParameter("paramsList");
        return cmsOrderLogisticaskService.getLogisticDetail(paramsList);
    }

    @ApiOperation("关闭指定物流爬取任务(待签收超过7天或最后一条超过一个月未更新)")
    @RequestMapping(value = "/closeLogisticTask", method = RequestMethod.POST)
    public JSONObject closeLogisticTask(HttpServletRequest request){
        String paramsList = request.getParameter("paramsList");
        return cmsOrderLogisticaskService.closeLogisticTask(paramsList);
    }

    @ApiOperation("关闭指定物流爬取任务(已签收)")
    @RequestMapping(value = "/closeLogisticOverTask", method = RequestMethod.POST)
    public JSONObject closeLogisticOverTask(@ApiParam(value = "物流商编码", required = true) @RequestParam(value = "logisticCode") String logisticCode,
                                            @ApiParam(value = "物流单号", required = true) @RequestParam(value = "logisticNumber") String logisticNumber){
        return cmsOrderLogisticaskService.closeLogisticOverTask(logisticCode, logisticNumber);
    }

}
